const eventBus = {
  evnetList: [],
  $on(callbackFun, name) {
    if (this.evnetList.find((i) => i.name === name)) {
      this.evnetList = this.evnetList.filter((i) => i.name !== name);
    }
    this.evnetList = [...this.evnetList, { name, callbackFun }];
  },
  $emit(name, data = '') {
    if (!name) return;
    this.evnetList.forEach((element) => {
      if (name === element.name) {
        element.callbackFun(data);
      }
    });
  },
  $remove(name = '') {
    this.evnetList = this.evnetList.filter((i) => i.name !== name);
  },
};
export default eventBus;
